import ybRequest from '../index'
import { IAccount, ILoginResult } from './type'
import { IDataType } from '../types'

enum LoginAPI {
  VerfifyCode = '/user/getVertifyCodeImage',
  AccountLogin = '/user/login',
  LoginUserInfo = '/login/',
  UserMenus = '/role/', // role/1/menu
}

export function getVertifyCodeRequest() {
  // console.log('验证码service启动')
  const url = LoginAPI.VerfifyCode + '/?time =' + Math.random()
  // console.log(url)

  return ybRequest.get({
    url: url,
    showLoading: false,
  })
}

export function accountLoginRequest(account: IAccount) {
  // console.log("执行service:accountLoginRequest");

  // console.log(LoginAPI.AccountLogin)
  // console.log(account);

  return ybRequest.post<IDataType<ILoginResult>>({
    url: LoginAPI.AccountLogin,
    data: account,
  })
}

export function requestUserInfoById(id: number) {
  return ybRequest.get<IDataType>({
    url: LoginAPI.LoginUserInfo + id,
    showLoading: false,
  })
}

export function requestUserMenuByRoleId(id: number) {
  return ybRequest.get<IDataType>({
    url: LoginAPI.UserMenus + id + './menu',
  })
}
